/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.site.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.site.entity.SiteFriendlink;
import com.jeesite.modules.site.service.SiteFriendlinkService;

/**
 * 外部链接管理Controller
 * @author ben
 * @version 2018-05-01
 */
@Controller
@RequestMapping(value = "${adminPath}/site/siteFriendlink")
public class SiteFriendlinkController extends BaseController {

	@Autowired
	private SiteFriendlinkService siteFriendlinkService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public SiteFriendlink get(String id, boolean isNewRecord) {
		return siteFriendlinkService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("site:siteFriendlink:view")
	@RequestMapping(value = {"list", ""})
	public String list(SiteFriendlink siteFriendlink, Model model) {
		model.addAttribute("siteFriendlink", siteFriendlink);
		return "modules/site/siteFriendlinkList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("site:siteFriendlink:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<SiteFriendlink> listData(SiteFriendlink siteFriendlink, HttpServletRequest request, HttpServletResponse response) {
		Page<SiteFriendlink> page = siteFriendlinkService.findPage(new Page<SiteFriendlink>(request, response), siteFriendlink); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("site:siteFriendlink:view")
	@RequestMapping(value = "form")
	public String form(SiteFriendlink siteFriendlink, Model model) {
		model.addAttribute("siteFriendlink", siteFriendlink);
		return "modules/site/siteFriendlinkForm";
	}

	/**
	 * 保存外部链接
	 */
	@RequiresPermissions("site:siteFriendlink:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated SiteFriendlink siteFriendlink) {
		siteFriendlinkService.save(siteFriendlink);
		return renderResult(Global.TRUE, "保存外部链接成功！");
	}
	
	/**
	 * 停用外部链接
	 */
	@RequiresPermissions("site:siteFriendlink:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(SiteFriendlink siteFriendlink) {
		siteFriendlink.setStatus(SiteFriendlink.STATUS_DISABLE);
		siteFriendlinkService.updateStatus(siteFriendlink);
		return renderResult(Global.TRUE, "停用外部链接成功");
	}
	
	/**
	 * 启用外部链接
	 */
	@RequiresPermissions("site:siteFriendlink:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(SiteFriendlink siteFriendlink) {
		siteFriendlink.setStatus(SiteFriendlink.STATUS_NORMAL);
		siteFriendlinkService.updateStatus(siteFriendlink);
		return renderResult(Global.TRUE, "启用外部链接成功");
	}
	
	/**
	 * 删除外部链接
	 */
	@RequiresPermissions("site:siteFriendlink:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(SiteFriendlink siteFriendlink) {
		siteFriendlinkService.delete(siteFriendlink);
		return renderResult(Global.TRUE, "删除外部链接成功！");
	}
	
}